<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Printer
{
	private $ci;
	private $mpdf;

	public function __construct()
	{
		$this->ci =& get_instance();
		$this->ci->load->library('mpdf');
		$this->init();
	}
	
	
	public function init($mode = 'c',$format ='A4',$font_size='',$font='',$m_left ='',$m_right = '',$m_top ='',$m_bottom='',$m_header ='',$m_footer='')
	{
		$this->mpdf= new mPDF($mode,$format,$font_size,$font,$m_left,$m_right,$m_top,$m_bottom,$m_header,$m_footer);
		$this->mpdf->SetDisplayMode('fullpage');
		$this->mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
		return $this;
	}
	
	public function watermark($string = 'Water Mark',$angle = 0 , $font_size)
	{
		$this->mpdf->SetWatermarkText($string);
		$this->mpdf->showWatermarkText = true;
		$this->mpdf->watermarkImageAlpha = 0.1;
		return $this;
	}
	
	public function footer($footer = '')
	{
		$this->mpdf->SetFooter($footer);
		return $this;
	}
	
	public function header($header = '')
	{
		$this->mpdf->SetHeader($header);
		return $this;
	}
	
	public function watermark_img($path,$opacity = 0.1,$x = 10,$y = 10)
	{
		$this->mpdf->SetWatermarkImage($path,$opacity,$x,$y);
		$this->mpdf->showWatermarkImage = true;
		$this->mpdf->watermarkImageAlpha = $opacity;
		return $this;
	}
	
	public function generate($html,$filename = FALSE,$save = FALSE,$type = 'I')
	{
		$this->mpdf->WriteHTML($html);
		$filename = $filename == FALSE ? date('m-d-y') : $filename;
		
		if($save == FALSE)
		{	
			$this->mpdf->Output($filename,$type);
		}else{
			$this->mpdf->Output($save.'/'.$filename.'.pdf','F');
		}
	}
}